package com.gopi.remfilebrowser.util;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.swing.text.NumberFormatter;

public class FileProperty 
{
	private boolean isFile;
	private int fileCount;
	private int folderCount;
	private String fileName;
	private String filePath;
	private long fileSize;
	
	public static final long KILO_BYTE = 1000;
	public static final long MEGA_BYTE = KILO_BYTE*1000L;
	public static final long GIGA_BYTE = MEGA_BYTE*1000L;
	
	public int getFileCount() {
		return fileCount;
	}
	public void setFileCount(int fileCount) {
		this.fileCount = fileCount;
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public String getFilePath() {
		return filePath;
	}
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	public long getFileSize() {
		return fileSize;
	}
	public void setFileSize(long fileSize) {
		this.fileSize = fileSize;
	}
	public int getFolderCount() {
		return folderCount;
	}
	public void setFolderCount(int folderCount) {
		this.folderCount = folderCount;
	}
	public boolean isFile() {
		return isFile;
	}
	public void setFile(boolean isFile) {
		this.isFile = isFile;
	}
	public String getFolderSize()
	{
		return fileCount + " File(s), " + folderCount + " folder(s)";
	}
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		sb.append("Name : " + fileName + "\n");
		sb.append("Path : " + filePath + "\n");
		sb.append("Size : " + fileSize + "\n");
		if(!isFile)
		{
			sb.append("Files : " + fileCount + "\n");
			sb.append("Folders : " + folderCount + "\n");
		}
		return sb.toString();
	}
	
	public String getGoodFileSize()
	{
		return getGoodFileSize(this);
	}
	
	public static String getGoodFileSize(FileProperty prop)
	{
		double size = (double) prop.getFileSize();
		if(size > KILO_BYTE)
		{
			if(size > MEGA_BYTE)
			{
				if(size > GIGA_BYTE)
				{
					return getWith2Precision(size/GIGA_BYTE) + " GigaByte" ;
				}
				else
				{
					return getWith2Precision(size/MEGA_BYTE) + " MegaBytes";
				}
			}
			else
			{
				return getWith2Precision(size/KILO_BYTE) + " KiloBytes";
			}
		}
		else
		{
			return size + " Bytes";
		}
	}
	
	public static String getWith2Precision(double no)
	{
		NumberFormat format = new DecimalFormat("#.00");
		return format.format(no);
		
	}
}
